package cn.tedu._05mvcboot04.common.response;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor//全参构造器
@NoArgsConstructor//无参构造器
public class JsonResult {
    private String message;
    private Object data;
    private Integer state;
    //不带data的构造方法
    public JsonResult(StatusCode statusCode) {
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
    }
    //带data的构造方法
    public JsonResult(StatusCode statusCode, Object data) {
        this.state=statusCode.getState();
        this.message=statusCode.getMessage();
        this.data=data;
    }
    //带data的静态方法
    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }
    //不带data的静态方法
    public static JsonResult ok() {
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }
    //带data的静态方法
    public static JsonResult fail(Object data) {
        return new JsonResult(StatusCode.OPERATION_FAILED,data);
    }
    //不带data的静态方法
    public static JsonResult fail() {
        return new JsonResult(StatusCode.OPERATION_FAILED);
    }
}
